from rest_framework.generics import ListAPIView
from rest_framework.permissions import IsAuthenticated
from .serializers import CouponModelSerializer, UserCouponModelSerializer
from . import models


class UserCouponAPIView(ListAPIView):
    """
    用户优惠券视图
    """
    # queryset = models.UserCoupon.objects.filter(is_show=True, is_deleted=False, is_use=False)

    serializer_class = UserCouponModelSerializer

    permission_classes = [IsAuthenticated, ]

    def get_queryset(self):
        user_id = self.request.user.id
        return models.UserCoupon.objects.filter(is_show=True, is_deleted=False, is_use=False, user_id=user_id)

